function where_id(temp_string) {
    if (temp_string == "translation_status") {
        return 1;
    }else if (temp_string == "translation_on") {
        return 2;
    }else if (temp_string == "translation_off") {
        return 3;
    }
    
}

// 在后台服务工作者脚本（background.js）中
chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
    console.log(message.action);
    console.log(where_id(message.action));
    switch (where_id(message.action)) {
        case 1:
            chrome.storage.local.get(["translation_status"], function (result) {
                if (!result.translation_status) {
                    chrome.storage.local.set(
                        { translation_status: "off" },
                        function () {
                            console.log("翻译状态设置为 'off'");
                        }
                    );
                    sendResponse({ result: { code: 200, message: "off" } });
                    return true; // 表示你将异步地调用sendResponse
                }
                sendResponse({
                    result: { code: 200, message: result.translation_status },
                });
                return true; // 表示你将异步地调用sendResponse
            });
            break;
        case 2:
            chrome.storage.local.set({ translation_status: "on" }, function () {
                console.log("翻译状态设置为 'on'");
            });
            sendResponse({ result: { code: 200, message: "on" } });
            return true; // 表示你将异步地调用sendResponse
            break;
        case 3:
            chrome.storage.local.set(
                { translation_status: "off" },
                function () {
                    console.log("翻译状态设置为 'off'");
                }
            );
            sendResponse({ result: { code: 200, message: "off" } });
            return true; // 表示你将异步地调用sendResponse
            break;

        default:
            break;
    }
});
